import java.util.Stack;

class Solution {
    public static void main(String[] args) {
        Solution s = new Solution();

    }

    public int evalRPN(String[] tokens) {
        /**
         * 逆波兰表达式求值
         * 解法：使用栈进行模拟*/
        int tmp = 0;
        Stack<Integer> stack = new Stack<>();
        for(int i = 0; i < tokens.length; i++) {
            if(!tokens[i].equals("+") &&
                    !tokens[i].equals("-") &&
                    !tokens[i].equals("*") &&
                    !tokens[i].equals("/")) {
                //将字符串转换为数组 然后入栈
                tmp = Integer.parseInt(tokens[i]);
                stack.push(tmp);
            } else {
                //出栈，运算，入栈
                int num2 = stack.pop();
                int num1 = stack.pop();
                switch(tokens[i]) {
                    case "+":{
                        tmp = num1+num2;
                        break;
                    }
                    case "-":{
                        tmp = num1-num2;
                        break;
                    }
                    case "*":{
                        tmp = num1*num2;
                        break;
                    }
                    case "/":{
                        tmp = num1/num2;
                        break;
                    }
                }
                stack.push(tmp);
            }
        }
        return stack.peek();
    }
}